package eerbaar.v2.client.ui;

import eerbaar.elements.extension.IPoints;
import eerbaar.extension.IExtensible;
import eerbaar.game.IGame;
import eerbaar.message.lib.ScoreChangeMsg;
import eerbaar.persona.IPersona;
import eerbaar.shared.message.IMessageReader;
import eerbaar.shared.message.Message;
import eerbaar.shared.message.MsgHelper;
import eerbaar.v2.app.GameHelper;
import eerbaar.v2.app.core.IGamePanelListener;

public class ScorePanel extends GameStatusPanel {

    public ScorePanel(IGamePanelListener listener) {
        super(listener, "Score:", 0);
        init();
    }

    private void init() {

        IMessageReader reader = new IMessageReader() {

            @Override
            public boolean read(Message msg) {

                IGame game = GameHelper.getGame();
                IPersona pet = game.getPersona("pet");
                IExtensible e = pet;
                int points = e.getExtension(IPoints.class).getPoints();
                ScorePanel.this.setValue(points);

                return false;
            }
        };

        MsgHelper.registerReader(ScoreChangeMsg.class, reader);
    }

}
